/// <reference types="cypress" />

// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add('login', (email, password) => { ... })

const { choiceUserPool, visitUrl } = require('../utils/common-utils')

Cypress.Commands.add('getElementAssertText', (element, expected) => {
  return cy.get(element).should('contain', expected)
})

Cypress.Commands.add('login', () => {
  cy.visit('/login')
  cy.get('#rc-tabs-0-tab-password').click()
  cy.fixture('login').then((userData) => {
    cy.get('#passworLogin_account').type(userData.username)
    cy.get('#passworLogin_password').type(userData.password)
  })

  cy.get('.authing-agreements-checkbox').click()
  cy.get('.authing-g2-submit-button').click()
  cy.get('.g2-completeInfo-header-skip').click()
  cy.url().should('include', '/console')
  choiceUserPool()
})

Cypress.Commands.add('visitMainMenuPwdScy', () => {
  visitUrl('safety-management/password')
})

Cypress.Commands.add('visitUserManager', () => {
  visitUrl('user')
})

Cypress.Commands.add('visitOrgManager', () => {
  visitUrl('org')
})

Cypress.Commands.add('visitBuiltApps', () => {
  visitUrl('application/self-built-apps')
})

//
//
// -- This is a child command --
// Cypress.Commands.add('drag', { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add('dismiss', { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite('visit', (originalFn, url, options) => { ... })
